package com.google.code.coma.space;

import com.google.code.coma.domain.Part;
import org.mozartspaces.capi3.Capi3Exception;
import org.mozartspaces.capi3.javanative.operation.NativeEntry;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;

/**
 * @author Dominik Strasser, dominikstr@gmail.com
 */
public class IdSelectorCallback implements SelectorCallback {
	private Set<String> keys;

	public IdSelectorCallback(Set<String> keys) {
		this.keys = keys;
	}

	@Override
	public List<NativeEntry> doInTransaction(Collection<NativeEntry> coordinatorCollection, CallContext callContext) throws Capi3Exception {
		List<NativeEntry> resultList = new ArrayList<NativeEntry>();
		for (NativeEntry e : coordinatorCollection) {
			if (keys.contains(((Part) e.getData()).getId())) {
				resultList.add(e);
			}
		}
		return resultList;
	}
}
